home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2002 November / CD 1 / APC0211D1.ISO / workshop / prog / files / ActivePerl-5.6.1.633-MSWin32.msi / _dd4c612535b9fc7ceb92dfbac449d65b < prev    next >
Encoding:
Text File  |  2002-06-18  |  4.5 KB  |  177 lines

  1. package Win32;
  2.  
  3. #
  4. #  Documentation for all Win32:: functions are in Win32.pod, which is a
  5. #  standard part of Perl 5.6, and later.
  6. #
  7.  
  8. BEGIN {
  9.     use strict;
  10.     use vars qw|$VERSION @ISA @EXPORT @EXPORT_OK|;
  11.  
  12.     require Exporter;
  13.     require DynaLoader;
  14.  
  15.     @ISA = qw|Exporter DynaLoader|;
  16.     $VERSION = '0.191';
  17.  
  18.     @EXPORT = qw(
  19.     NULL
  20.     WIN31_CLASS
  21.     OWNER_SECURITY_INFORMATION
  22.     GROUP_SECURITY_INFORMATION
  23.     DACL_SECURITY_INFORMATION
  24.     SACL_SECURITY_INFORMATION
  25.     MB_ICONHAND
  26.     MB_ICONQUESTION
  27.     MB_ICONEXCLAMATION
  28.     MB_ICONASTERISK
  29.     MB_ICONWARNING
  30.     MB_ICONERROR
  31.     MB_ICONINFORMATION
  32.     MB_ICONSTOP
  33.     );
  34.     @EXPORT_OK = qw(
  35.         GetOSName
  36.         SW_HIDE
  37.         SW_SHOWNORMAL
  38.         SW_SHOWMINIMIZED
  39.         SW_SHOWMAXIMIZED
  40.         SW_SHOWNOACTIVATE
  41.     );
  42. }
  43.  
  44. # Routines available in core:
  45. # Win32::GetLastError
  46. # Win32::LoginName
  47. # Win32::NodeName
  48. # Win32::DomainName
  49. # Win32::FsType
  50. # Win32::GetCwd
  51. # Win32::GetOSVersion
  52. # Win32::FormatMessage ERRORCODE
  53. # Win32::Spawn COMMAND, ARGS, PID
  54. # Win32::GetTickCount
  55. # Win32::IsWinNT
  56. # Win32::IsWin95
  57.  
  58. # We won't bother with the constant stuff, too much of a hassle. Just hard
  59. # code it here.
  60.  
  61. sub NULL ()                { 0 }
  62. sub WIN31_CLASS ()            { &NULL }
  63.  
  64. sub OWNER_SECURITY_INFORMATION ()    { 0x00000001 }
  65. sub GROUP_SECURITY_INFORMATION ()    { 0x00000002 }
  66. sub DACL_SECURITY_INFORMATION  ()    { 0x00000004 }
  67. sub SACL_SECURITY_INFORMATION  ()    { 0x00000008 }
  68.  
  69. sub MB_ICONHAND        ()        { 0x00000010 }
  70. sub MB_ICONQUESTION    ()        { 0x00000020 }
  71. sub MB_ICONEXCLAMATION    ()        { 0x00000030 }
  72. sub MB_ICONASTERISK    ()        { 0x00000040 }
  73. sub MB_ICONWARNING    ()        { 0x00000030 }
  74. sub MB_ICONERROR    ()        { 0x00000010 }
  75. sub MB_ICONINFORMATION    ()        { 0x00000040 }
  76. sub MB_ICONSTOP        ()        { 0x00000010 }
  77.  
  78. sub SW_HIDE           ()        { 0 }
  79. sub SW_SHOWNORMAL     ()        { 1 }
  80. sub SW_SHOWMINIMIZED  ()        { 2 }
  81. sub SW_SHOWMAXIMIZED  ()        { 3 }
  82. sub SW_SHOWNOACTIVATE ()        { 4 }
  83.  
  84.  
  85. ### This method is just a simple interface into GetOSVersion().  More
  86. ### specific or demanding situations should use that instead.
  87.  
  88. my ($found_os, $found_desc);
  89.  
  90. sub GetOSName {
  91.     my ($os,$desc,$major, $minor, $build, $id)=("","");
  92.     unless (defined $found_os) {
  93.         # If we have a run this already, we have the results cached
  94.         # If so, return them
  95.  
  96.         # Use the standard API call to determine the version
  97.         ($desc, $major, $minor, $build, $id) = Win32::GetOSVersion();
  98.  
  99.         # If id==0 then its a win32s box -- Meaning Win3.11
  100.         #  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/sysinfo_49iw.asp
  101.         unless($id) {
  102.             $os = 'Win32s';
  103.         }
  104.     else {
  105.         # Magic numbers from MSDN documentation of OSVERSIONINFO
  106.         # Here is some mickeysoft code that tells the story as well:
  107.         # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/sysinfo_92jy.asp
  108.         # Caution with the above code as it uses functions unavailable
  109.         # to us in Perl.
  110.         # Most version names can be parsed from just the id and minor
  111.         # version
  112.         $os = {
  113.         1 => {
  114.             0  => "95",
  115.             10 => "98",
  116.             90 => "Me"
  117.         },
  118.         2 => {
  119.             0  => "2000",
  120.             1  => "XP/.Net",
  121.             51 => "NT3.51"
  122.         }
  123.         }->{$id}->{$minor};
  124.     }
  125.  
  126.         # This _really_ shouldnt happen. At least not for quite a while
  127.         # Politely warn and return undef
  128.         unless (defined $os) {
  129.             warn qq[Windows version [$id:$major:$minor] unknown!];
  130.             return undef;
  131.         }
  132.  
  133.         my $tag = "";
  134.  
  135.         # But distinguising W2k from NT4 requires looking at the major version
  136.         if ($os eq "2000" && $major != 5) {
  137.             $os = "NT4";
  138.         }
  139.  
  140.         # For the rest we take a look at the build numbers and try to deduce
  141.     # the exact release name, but we put that in the $desc
  142.         elsif ($os eq "95") {
  143.             if ($build eq '67109814') {
  144.                     $tag = '(a)';
  145.             }
  146.         elsif ($build eq '67306684') {
  147.                     $tag = '(b1)';
  148.             }
  149.         elsif ($build eq '67109975') {
  150.                     $tag = '(b2)';
  151.             }
  152.         }
  153.     elsif ($os eq "98" && $build eq '67766446') {
  154.             $tag = '(2nd ed)';
  155.         }
  156.  
  157.     if (length $tag) {
  158.         if (length $desc) {
  159.             $desc = "$tag $desc";
  160.         }
  161.         else {
  162.             $desc = $tag;
  163.         }
  164.     }
  165.  
  166.         # cache the results, so we dont have to do this again
  167.         $found_os      = "Win$os";
  168.         $found_desc    = $desc;
  169.     }
  170.  
  171.     return wantarray ? ($found_os, $found_desc) : $found_os;
  172. }
  173.  
  174. bootstrap Win32;
  175.  
  176. 1;
  177.